import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import query from '@dfeidao/atom-nodejs/db/query';
import { systemid, productid } from '../../atom/config';
import count from '@dfeidao/atom-nodejs/db/count';

interface Message {
	filter: {
		page_no: number,
		hidden_source: string[]
	}
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}
export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:e:\Feidao\kh\src\risk-point\zj-000006\s002,action_id:' + action_id);

	const { prepare, exec } = query(action_id, session_id, systemid);
	prepare('hazard_source', ['hidden_source', 'hidden_name', 'hidden_code', 'control_level', 'engineer_skill', 'duty_department', 'responsible'], { productid, hidden_source: { $in: message.filter.hidden_source } }, 5, 1, [], []);
	const [data] = await exec();

	//数据总量
	const { prepare: p, exec: e } = count(action_id, session_id, systemid);
	p('hazard_source', { productid });
	const [n] = await e();

	log('Service end path:e:\Feidao\kh\src\risk-point\zj-000006\s002,action_id:' + action_id);
	return {
		data: { data, n }
	};
}
